<template>
  <div>
    <div class="uploadImg">
      <el-upload action="#" :http-request="handleUpload" ref="upload" :file-list="fileList"
        :auto-upload="false">
        <el-button slot="trigger" size="small">选取文件</el-button>
        <el-button style="margin-left: 10px;" size="small" type="primary" @click="submitUpload">上传</el-button>
      </el-upload>
    </div>
  </div>
</template>
<script>
export default {
  name: '',
  components: {

  },
  mixins: [],
  props: {

  },
  data() {
    return {
      fileList: []
    }
  },
  computed: {

  },
  watch: {

  },
  mounted() {

  },
  methods: {
    submitUpload() {
      this.$refs.upload.submit()
    },
    handleUpload(params) {
      const userInfo = JSON.parse(sessionStorage.getItem('userInfo'))

      const formdata = new FormData()
      formdata.append('id', userInfo.id)
      formdata.append('carousel', params.file)

      this.$axios.post('carousel/backend/add', formdata, {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }).then(res => {
        if (res.data.code === 1) {
          this.$message(res.data.message)
          this.getImage()
        } else {
          this.$message(res.data.message)
        }
      })
    }
  }
};
</script>
<style lang='' scoped>
</style>